package visualizer;

import visualizer.drawable.AbstractDrawable;
import visualizer.drawable.Drawable;
import visualizer.drawable.DrawableCollection;
import visualizer.graphics.HsbColor;
import processing.core.PFont;
import processing.core.PGraphics;

public class Bar extends AbstractDrawable {
	private static final float PI = (float) 3.14159265358979323846;
	int x;
	int y;
	float width;
	float height;
	float depth;
	HsbColor color1;
	HsbColor colorStroke;
	String strl;
	boolean doubleBarUnder;
	App a;
	
	public Bar(int x, int y, float width, float height, float depth, HsbColor color, HsbColor colorStroke, String strl, App a, boolean doubleBarUnder) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		this.depth = depth;
		this.color1 = color;
		this.colorStroke = colorStroke;
		this.strl = strl;
		this.a = a;
		this.doubleBarUnder = doubleBarUnder;
	}
	
	public void draw(PGraphics g){
//		if(doubleBarUnder){
//			drawShadow(g);
//		}
		
		color1.fill(g);
		colorStroke.stroke(g);
		g.rect(x, y, width, height);
		
		if(!doubleBarUnder){
			drawTopBox(g);
		}		
		drawSideBox(g);

		if(!doubleBarUnder){
			int fontSize = 32;
			PFont myFont = a.createFont("Arial", fontSize);
			g.textFont(myFont);
			
			g.pushMatrix();
			g.rotate(-PI/2);
			g.text(strl, -(y-30), (float) (x+width));
			g.popMatrix();
		}
	}

	private void drawShadow(PGraphics g) {
		int colorS = g.color(140,140,140); 
		g.fill(colorS);
		float x1 = x;
		float y1 = y+height;
		float x2 = x+width+10;
		float y2 = y+height;
		float x3 = (float) (x+width+10+depth*Math.cos(PI/6));
		float y3 = (float) (y+height-10-depth*Math.sin(PI/6));
		float x4 = (float) (x+depth*Math.cos(PI/6));
		float y4 = (float) (y+height-10-depth*Math.sin(PI/6));
		g.quad(x1,y1 , x2,y2 , x3,y3, x4,y4);
	}

	public String annaOtsikko(){
		return strl;
	}
	
	private void drawTopBox(PGraphics g) {
		float xx1 = x;
		float yy1 = y;
		float xx2 = (float) (x+depth*Math.cos(PI/4));
		float yy2 = (float) (y-depth*Math.sin(PI/4));
		float xx3 = (float) (x+width+depth*Math.cos(PI/4));
		float yy3 = (float) (y-depth*Math.sin(PI/4));
		float xx4 = x+width;
		float yy4 = y;
		g.quad(xx1,yy1 , xx2,yy2 , xx3,yy3, xx4,yy4);
	}

	private void drawSideBox(PGraphics g) {
		float x1 = x+width;
		float y1 = y;
		float x2 = x+width;
		float y2 = y+height;
		float x3 = (float) (x+width+depth*Math.cos(PI/4));
		float y3 = (float) (y+height-depth*Math.sin(PI/4));
		float x4 = (float) (x+width+depth*Math.cos(PI/4));
		float y4 = (float) (y-depth*Math.sin(PI/4));
		g.quad(x1,y1 , x2,y2 , x3,y3, x4,y4);
	}

}
